// pages/xukexujingquanyicesuan/xukexujingquanyicesuan.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

    show: false,

    riqi: [{
        qixian: '定期3个月',
        idqi: 3,

      },
      {
        qixian: '定期6个月',
        idqi: 6,

      },
      {
        qixian: '定期1年',
        idqi: 12,

      }
    ],

    BAL: '',
    qixian: '',
    idqi: '',
    cefen: '',
    CON_TYPE: '',

    cekuan: true,
  },


  gunabi() {
    this.setData({
      qixian:'',
      cekuan: true,
      BAL: '',
      cefen: '',
    });

  },

  kaice(e) {
    console.log(e.currentTarget.id);
    this.setData({
      CON_TYPE: e.currentTarget.id,
      cekuan: false,
    });
  },




  back() {
    wx.navigateBack({
      delta: 1
    })
  },















  xuanyoudi() {


    if (this.data.BAL == '') {

      wx.showModal({
        title: '温馨提示',
        content: '请先输入存款信息',
        success: function (res) {
          if (res.confirm) { //这里是点击了确定以后   
            console.log('用户点击确定')
          } else { //这里是点击了取消以后
            console.log('用户点击取消')
          }
        }
      })
    } else if (this.data.BAL < 5 || this.data.BAL > 1000) {
      wx.showModal({
        title: '温馨提示',
        content: '输入数字不能小于5或大于1000',
        success: function (res) {
          if (res.confirm) { //这里是点击了确定以后   
            console.log('用户点击确定')
          } else { //这里是点击了取消以后
            console.log('用户点击取消')
          }
        }
      })
      this.setData({
        BAL: '',
      });

    } else {



      this.setData({
        show: true
      });

    }
  },

  onClose() {
    this.setData({
      show: false
    });
  },





  yier(e) {
    this.setData({
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
      CUSTOMER_ID: app.globalData.CUSTOMER_ID,
    });

    console.log(e);

    console.log(e.currentTarget.dataset.item.idqi);
    console.log(e.currentTarget.dataset.item.qixian);
    this.setData({
      show: false,
      qixian: e.currentTarget.dataset.item.qixian,
      idqi: e.currentTarget.dataset.item.idqi,
    });


    wx.request({
      url: app.globalData.interface + '/crossVersionOne/API2_2204_comparisonXuKeXuJin',
      method: 'POST',
      data: {

        CON_MONEY: this.data.BAL,
        CON_TYPE: this.data.CON_TYPE,
        CON_YUE: this.data.idqi,
        OPEN_ID: this.data.openid, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        console.log(res.data.data);
        console.log(res);

        let that = this

        if (res.data.result == 'success') {
          that.setData({

            cefen: res.data.data + '元优惠券',
          })
        } else {
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后   

                console.log('用户点击确定')
              } else { //这里是点击了取消以后

                console.log('用户点击取消')
              }
            }
          })
        }
      }
    })


  },


















  handleInput(e) {

    console.log(e);
    let value = this.validateNumber(e.detail.value)

    console.log(value);


    this.setData({
      BAL: value
    })



  },
  validateNumber(val) {
    return val.replace(/\D/g, '')
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      openid: app.globalData.openid,
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,
      CUSTOMER_ID: app.globalData.CUSTOMER_ID,
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})